package presentation;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import db.DbUtils;
import db.Picture;

public class Get16Images extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Session hbSession = DbUtils.startSession();
		String pageNumberStr = request.getParameter("pageNumber");
		int pageNumber = 0;
		try {
			pageNumber = Integer.parseInt(pageNumberStr);
			List<Picture> pictures = DbUtils.get16Pictures(hbSession, pageNumber);
			request.setAttribute("pictures", pictures);
			request.getRequestDispatcher("Home.jsp").forward(request, response);
		}catch (Exception e) {
			response.sendRedirect("Error.jsp");
		}
	}

}
